package com.srit.system.service.impl;

import java.util.Iterator;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.srit.system.bean.Grid;
import com.srit.system.bean.GridAttrRel;
import com.srit.system.dao.GridAttrRelDao;
import com.srit.system.dao.GridDao;
import com.srit.system.service.GridService;

@Service
@Transactional
public class GridServiceImpl implements GridService {
	@Autowired
	private GridDao gridDao;
	@Autowired
	private GridAttrRelDao gridAttrRelDao;

	@Override
	public void save(Grid grid) {
		gridDao.save(grid);
		int gridId = gridDao.getMaxId();
		for (Iterator<GridAttrRel> it = grid.getRelList().iterator(); it
				.hasNext();) {
			GridAttrRel rel = it.next();
			rel.setGridId(gridId);
			gridAttrRelDao.save(rel);
		}

	}

}
